<?php

namespace app\controller;

use app\BaseController;
use app\services\BlackService;
use app\validate\BlackValidate;
use think\App;
use think\Container;

class BlackController extends BaseController
{
    /**
     * @var BlackService
     */
    private $service;

    public function __construct(App $app)
    {


        parent::__construct($app);
    }

    public function queryFlight(){
        $this->service = new BlackService($this->request->bcw ??['data'=>[]]);
        $param = $this->request->param(['fly_day', 'voyage', 'airlines','fly_time']);

        validate(BlackValidate::class)
            ->scene('avho')
            ->check($param);



        return $this->returnJson($this->service->AVHO(strtotime($param['fly_day']), $param['voyage'], $param['fly_time'], $param['airlines']));
    }

    public function queryFlightSeatPrice(){
        $this->service = new BlackService($this->request->bcw ??['data'=>[]]);
        $param = $this->request->param(['fly_day', 'fly_time00', 'voyage', 'flight_no', 'seat']);
        validate(BlackValidate::class)
            ->scene('sd')
            ->check($param);
        return $this->returnJson($this->service->queryFlightSeatPrice(strtotime($param['fly_day']), $param['fly_time00'], $param['voyage'], $param['flight_no'],$param['seat']));
    }

    public function clear(){
        $this->service = new BlackService($this->request->bcw ??['data'=>[]]);
        $this->service->I();
        return $this->returnJson();
    }
    public function ff(){
        $this->service = new BlackService($this->request->bcw ??['data'=>[]]);
        $param = $this->request->param(['fly_day','flight_no']);

        validate(BlackValidate::class)
            ->scene('ff')
            ->check($param);
        return $this->returnJson( $this->service->ff(strtotime($param['fly_day']), $param['flight_no']));
    }


    public function getCHDPrice(){
        $this->service = new BlackService($this->request->bcw ??['data'=>[]]);
        $param = $this->request->param(['fly_day', 'fly_time00', 'voyage', 'flight_no', 'seat', 'top_seat']);
        validate(BlackValidate::class)
            ->scene('sd')
            ->check($param);
        $result = [];
        empty($param['seat'])||$result[$param['seat']] = $this->service->queryCHDSeatPrice(strtotime($param['fly_day']), $param['fly_time00'], $param['voyage'], $param['flight_no'], $param['seat'], false);
        empty($param['top_seat']) || $result[$param['top_seat']] = $this->service->queryCHDSeatPrice(strtotime($param['fly_day']), $param['fly_time00'], $param['voyage'], $param['flight_no'], $param['top_seat']);

        return $this->returnJson($result);
    }


    public function getINFTPrice(){
        $this->service = new BlackService($this->request->bcw ??['data'=>[]]);
        $param = $this->request->param(['fly_day', 'fly_time00', 'voyage', 'flight_no', 'seat']);
        validate(BlackValidate::class)
            ->scene('sd')
            ->check($param);
        return $this->returnJson([$param['seat']=>$this->service->queryINFTSeatPrice(strtotime($param['fly_day']), $param['fly_time00'], $param['voyage'], $param['flight_no'], $param['seat'])]);

    }





}